package com.abou.mvc.controller.admin.product;

import java.util.List;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import com.abou.mvc.controller.ACommonController;
import com.abou.mvc.controller.ControllerUtils;
import com.abou.mvc.controller.admin.HomeController;

/**
 * The controller for the products delete page.
 * 
 * @author vvvq5150
 */
@Controller
@RequestMapping("admin/product/delete.do")
public class DeleteProductController extends ACommonController {
  
  /**
   * The name for this view
   */
  public static final String VIEW_NAME = "admin/product/delete";
  
  /**
   * The empty constructor
   */
  public DeleteProductController() {

    super(VIEW_NAME, HomeController.VIEW_NAME, true);
  }
  
  /**
   * Receives the form data and handles it.
   * 
   * @param productIds The product IDs list
   * @return The view to display
   * @throws Exception
   */
  @RequestMapping(method = RequestMethod.GET)
  public String submitForm(@RequestParam List<Integer> productIds)
      throws Exception {

    // deleting the products
    for (Integer productId : productIds) {
      
      getProductManager().deleteProduct(productId);
    }
    
    // redirecting to the search triggers page
    return ControllerUtils.REDIRECT_INSTR + HomeController.VIEW_NAME
        + ControllerUtils.VIEW_NAME_SUFFIX + ControllerUtils.PARAMS_DEL
        + ControllerUtils.CONFIRMATION_ATT + ControllerUtils.PARAMS_VAL_SEP
        + ControllerUtils.DELETED_CONFIRMATION;
  }
}
